package project.euler.honk.problem.to50;

final class Problem26 {

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		int max = 0;
		int value = 0;
		for (int i = 7; i < 1000; i++) {
			int tmp = cycleLength(i);
			if (tmp > max) {
				value = i;
				max = tmp;
			}
		}
		long end = System.currentTimeMillis();
		System.out.println("Result: " + value + " Time: " + (end - start));
	} 

	private static int cycleLength(int y) {
		int x = 1;

		final int[] rests = new int[10 * y];

		for (int pos = 0;; pos++) {
			x = (x * 10) % y;
			if (x == 0)
				return 0;
			final int p = 10 * x + x / y;
			if (rests[p] != 0)
				return pos - rests[p];
			else
				rests[p] = pos;
		}
	}

}
